<template>
  <div class='sub-category'>
    <!-- 主体区 -->
    <div class="container">
       <!-- 面包屑区域 -->
      <xtx-bread seperator='>'>
        <xtx-breadItem to="/">首页</xtx-breadItem>
        <xtx-breadItem :to="`/category/${subCategoryData.parentId}`">
          {{ subCategoryData.parentName }}
        </xtx-breadItem>
        <xtx-breadItem>{{subCategoryData.name }}</xtx-breadItem>
      </xtx-bread>
      <!-- 筛选区域 -->
       <!-- 筛选区 -->
      <div class="sub-filter">
        <!-- 规格  -->
        <div class="item" v-for="item in subCategoryData.saleProperties" :key="item.id">
          <div class="head">{{item.name}}：</div>
            <div class="body">
                <a :class="{active:selectedTag[item.name] == null}"  @click="toggleSelected(null, item)" href="javascript:;">全部</a>
              <div :key="one.id" v-for="one in item.properties">
                <a
                href="javascript:;"
                @click="toggleSelected(one, item)"
                :class="{active:selectedTag[item.name] && selectedTag[item.name].id===one.id}"
                >{{one.name}}</a>

            </div>

            </div>
        </div>
      </div>
      <!-- 排序区域 -->
      <div class="sub-sort">
        <div class="sort">
          <a
          v-for="item in sortTypeList"
          :key="item.type"
          href="javascript:;"
          @click="toggleSort(item.type)"
          :class="{active:curSortType===item.type}"
          >{{item.name}}</a>
        </div>
      </div>
      <!-- 商品列表 -->
      <div class="sort-list-container">
        <GoodsItem  v-for="good in goodList" :key="good.id" :goods="good"/>
      </div>
    </div>
    <!-- 下拉加载更多 -->
    <xtx-load :loadList='FetchFn' :isFinished='isfinished' :isLoading='isLoading'/>
  </div>
</template>

<script>
import { useLoadListData } from '@/views/category/service/useLoadListData'
import GoodsItem from '@/views/Home/components/home-goods.vue'
export default {
  name: 'SubCategory',
  components: {
    GoodsItem
  },
  setup () {
    // 面包屑导航数据
    // 加载筛选数据
    // 已选择标签 {[key]: value}
    const {
      toggleSelected,
      sortTypeList,
      toggleSort,
      curSortType,
      goodList,
      reqParams,
      loadList,
      isfinished,
      isLoading,
      subCategoryData,
      selectedTag,
      FetchFn
    } = useLoadListData()
    return {
      subCategoryData,
      toggleSelected,
      toggleSort,
      curSortType,
      sortTypeList,
      goodList,
      reqParams,
      selectedTag,
      loadList,
      isfinished,
      isLoading,
      FetchFn
    }
  }
}

</script>
<style scoped lang='less'>
.goods-list {
  background: #fff;
  padding: 0 25px;
  margin-top: 25px;
}
   // 筛选区
  .sub-filter {
    background: #fff;
    padding: 25px;
    .item {
      display: flex;
      padding: 10px 0;
      .head {
        width: 80px;
        color: #999;
      }
      .body {
        flex: 1;
        display: flex;
        overflow-wrap: anywhere;
        a {
          margin-right: 36px;
          transition: all .3s;
          &.active,
          &:hover {
            color: @xtxColor;
          }
        }
      }
    }
  }
  // 排序区
  .sub-sort {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .sort {
    display: flex;
    a {
      height: 30px;
      line-height: 28px;
      border: 1px solid #e4e4e4;
      padding: 0 20px;
      margin-right: 20px;
      color: #999;
      border-radius: 2px;
      position: relative;
      transition: all .3s;
      &.active {
        background: @xtxColor;
        border-color: @xtxColor;
        color: #fff;
      }
      .arrow {
        position: absolute;
        border: 5px solid transparent;
        right: 8px;
        &.up {
          top: 3px;
          border-bottom-color: #bbb;
            &.active {
            border-bottom-color: @xtxColor;
          }
        }
        &.down {
          top: 15px;
          border-top-color: #bbb;
          &.active {
            border-top-color: @xtxColor;
          }
        }
      }
    }
  }
  .check {
    .xtx-checkbox {
      margin-left: 20px;
      color: #999;
    }
  }
}
.list-container{
  margin-top: 20px;
  padding: 0 20px;
  background: #fff;
}
// 商品列表
.sort-list-container {
      display: flex;
      flex-wrap: wrap;
   }
</style>
